# -*- coding: UTF-8 -*-
"""
Create by Louis on 2019/7/21-22:26
"""
# __author__ = "Louis"
class Redprint:
    def __init__(self,name):
        self.name = name
        self.mount = []
    def route(self,rule,**options):
        def decorator(f):
            self.mount.append((f,rule,options))
            return f
        return  decorator
    def register(self,bp,url_prefix=None):
        #url_prefix ==None也可以
        if url_prefix is None:
            url_prefix = '/'  + self.name
        #元组解包拆分成各个元素方法
        for f,rule,options in self.mount:
            endpoint = options.pop("endpoint", f.__name__)
            bp.add_url_rule(url_prefix+rule, endpoint, f, **options)
